package eu.news.data.hibernate.dao;

import java.util.HashMap;
import java.util.Map;

import eu.news.config.Debugger;
import eu.news.data.dao.DAO;
import eu.news.data.dao.DAOFactory;
import eu.news.data.dao.InterfaceDAO;
import eu.news.data.dao.NewsDAO;
import eu.news.data.dao.OperatorDAO;
import eu.news.data.dao.PictureDAO;
import eu.news.data.dao.SortDAO;
import eu.news.data.dao.SpecialDAO;
import eu.news.data.dao.SysConfigDAO;
import eu.news.data.pojo.Entity;

public final class HibernateDAOFactory extends DAOFactory {
	private static Map<Class<? extends DAO<? extends Entity>>, Class<? extends DAO<? extends Entity>>> map = new HashMap<Class<? extends DAO<? extends Entity>>, Class<? extends DAO<? extends Entity>>>();

	static {
		map.put(NewsDAO.class, HB_NewsDAO.class);
		map.put(InterfaceDAO.class, HB_InterfaceDAO.class);
		map.put(OperatorDAO.class, HB_OperatorDAO.class);
		map.put(PictureDAO.class, HB_PictureDAO.class);
		map.put(SortDAO.class, HB_SortDAO.class);
		map.put(SpecialDAO.class, HB_SpecialDAO.class);
		map.put(SysConfigDAO.class, HB_SysConfigDAO.class);
	}
	
	@Override
	protected DAO<? extends Entity> getDAO(
			Class<? extends DAO<? extends Entity>> daoType) {
		Class<? extends DAO<? extends Entity>> _class = map.get(daoType);
		if (_class == null)
			return null;
		try {
			return _class.newInstance();
		} catch (InstantiationException e) {
			Debugger.printStackTrace(e);
		} catch (IllegalAccessException e) {
			Debugger.printStackTrace(e);
		}
		return null;
	}

}
